<html>
	<body>
		
	<?php
		include("users.php");
		$obj = new users();
		
		if(isset($_REQUEST['userId'])){
			$userId=$_REQUEST['userId'];
			
			$obj->search_byId($userId);
			$row=$obj->fetch();
		}


	?>		
	<form action="user_edit.php" method="GET">
		<table>
			<tr><td>Firstname: </td><td><input type="text" value="<?php echo $row['firstname']?>" name="firstname"></td></tr>
			<tr><td>Lastname: </td><td><input type="text" value="<?php echo $row['lastname']?>" name="lastname"></td></tr>
			<tr><td>Username: </td><td><input type="text" value="<?php echo $row['username']?>" name="username"></td></tr>
			<tr><td>Usertype: </td><td><select name="usertype" value="<?php echo $row['usertype'] ?>">
											<option> ADMIN </option>
											<option> CHO </option>
											<option> DHMT </option>
										 </select>	</td></tr>
			
			<input type="hidden" value="<?php echo $userId ?>" name="userId"> 
		</table>	
		<input type="submit" name="submit" value="EDIT">
	</form>
	
	<?php
		
		if(isset($_REQUEST['userId'])){
			$userId=$_REQUEST['userId'];
			$firstname=$_REQUEST['firstname'];
			$lastname=$_REQUEST['lastname'];
			$username=$_REQUEST['username'];
			$usertype=$_REQUEST['usertype'];
			
			if(!$obj->edit_user($firstname, $lastname,$username,$usertype,$userId)){
				echo "Error ".mysql_error();
			}else{
				echo "User editted";
			}
	
	}
	?>
	</body>
</html>
	